﻿@using Ext.Net;
@using Ext.Net.MVC;
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Login</title>
    @Styles.Render("~/Content/homeCss")
    @Scripts.Render("~/Scripts/homeJs")
    <style>
        .al_right {
            float: right;
        }
    </style>
</head>
<body style="background: #e1c192 url('../Content/bg2.jpg') repeat;">
    @(Html.X().ResourceManager())
    <div class="container">



        <header>

            <h1><strong>业务</strong>管理系统</h1>
            <h2></h2>


            <div class="support-note">
                <span class="note-ie">Sorry, only modern browsers.</span>
            </div>

        </header>

        <section class="main">
            @using (Html.BeginForm())
            {
                <div id="form1" class="form-2">

                    <h1><span class="log-in">Log in</span> or <span class="sign-up">sign up</span></h1>


                    <p class="float">
                        <label for="login"><i class="icon-user"></i>用户名：</label>
                        @(Html.X().TextField().Width(300).Name("loginName").Border(false).ID("loginName").AllowBlank(false))
                    </p>
                    <p class="float">
                        <label for="password"><i class="icon-lock"></i>密码：</label>
                        @(Html.X().TextField().InputType(Ext.Net.InputType.Password).Border(false).ID("loginPassword").Name("loginPassword").Width(300).AllowBlank(false))
                    </p>
                    <p class="float">
                        <label for="password"><i class="icon-lock"></i>验证码：</label>
                        @(Html.X().TextField().Width(300).Name("captcha").Border(false).ID("captcha"))

                    </p>
                    <p class="float">
                        <img id="CheckCodeImg" src="/Home/Captcha" alt="" onclick="RefreshCheckCode()" style="cursor: pointer;">
                    </p>
                    <p class="float"> &nbsp; </p>
                    <p class="float"> &nbsp; </p>
                    <p class="clearfix" style="margin:auto; margin-top:30px;text-align:center;">
                        <div style="float:left;width:35%;text-align:center;">
                            @(Html.X().Button().Text("登陆").ID("btnLogin").Icon(Icon.Accept).Width(80).OnClientClick("DoLogin"))
                        </div>
                        <div style="float:left;width:35%;text-align:center;">
                            @(Html.X().Button().Text("清除").ID("btnClear").Icon(Icon.Cancel).Width(80).OnClientClick("Clear"))
                        </div>
                        <div style="float:left;width:30%;text-align:center;">
                            @(Html.X().Button().Text("注册").ID("btnRegist").Icon(Icon.UserAdd).Width(80).OnClientClick("Regist"))
                        </div>
                    </p>
                </div>
            }
        </section>

    </div>


    <script type="text/javascript">
        function Regist() {
            window.open("Home/Regist")
        }

        function Clear() {
            App.loginPassword.setValue('');
            App.loginName.setValue('');
            App.captcha.setValue('');
        }

        var maskDiv;
        function DoLogin() {

            maskDiv = Ext.getBody().mask("系统登录中,请稍后...", '', 300);
            App.direct.Login(
                App.loginName.getValue(),
                App.loginPassword.getValue(),
                App.captcha.getValue(),{
                success: function (result) {
                    if (result.Result != "OK") {
                        Ext.Msg.alert('信息', result.Message);
                        RefreshCheckCode();
                        Clear();
                        Ext.getBody().unmask();
                    } else {
                        window.location.href = result.Message;
                    }
                },
                failure: function (error) {
                    Ext.Msg.alert('信息', error);
                    Ext.getBody().unmask();

                }
            });
        }

        function RefreshCheckCode() {
            var imgSrc = $("#CheckCodeImg");
            var src = imgSrc.attr("src");
            imgSrc.attr("src", chgUrl(src));
            //时间戳
            //为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳
            function chgUrl(url) {
                var timestamp = (new Date()).valueOf();
                urlurl = url.substring(0, 11);
                if ((url.indexOf("?") >= 0)) {
                    urlurl = url + "&t=" + timestamp;
                } else {
                    urlurl = url + "?t=" + timestamp;
                }
                return urlurl;
            }


        }

        $(function () {
            $(document).keydown(function (e) {
                if (e.keyCode == 13) {
                    DoLogin();
                }
            });

            //$.post('/TestBatis/List', {
            //    UserId:"aaaa"
            //}, function () {
            //});
        });
    </script>

</body>



</html>
